// 假设这是 fileUpload.js
const fs = require("fs");
const path = require("path");
console.log("123");

const fileUpload = async (file, options) => {
  console.log(file, options, "&&&&&F");

  try {
    const uploadDir = options.uploadDir || "./uploads";
    const filePath = path.join(uploadDir, file.newFilename);

    // 保存文件到指定目录
    await fs.promises.rename(file.path, filePath);

    // 返回上传结果
    return {
      success: true,
      data: filePath, // 假设返回文件保存路径
    };
  } catch (err) {
    console.error("File upload failed:", err);
    return {
      success: false,
      message: "File upload failed",
    };
  }
};

module.exports = fileUpload;
